<template>
  <div>
     <Row>
        <input v-model="gameId" placeholder="游戏id" ></input>
        <Date-picker v-model="startDay" placeholder="开始日期" format="yyyy-MM-dd"></Date-picker>
        <Date-picker v-model="endDay" placeholder="结束日期" format="yyyy-MM-dd"></Date-picker>
        <Button type="primary" @click="onSearch">查询</Button>
    </Row>
    <Table :border="true" :stripe="true" :show-header="true"  :width="1400" :data="tableData" :columns="tableColumns"></Table>
    <!--<Page class="bottom-page" :total="totalPage" :current="crtPage" :page-size="pageSize" show-total show-elevator @on-change="onChange"></Page>-->
  </div>
</template>
<script>

import {getRoleGameInfosTotal} from '@/api/game.js'
import {getVO} from '@/common/proto-vo.js'
export default {
  data () {
    return {
      gameId: '',
      startDay: '',
      endDay: '',
      crtPage: 1,
      totalPage: 0,
      pageSize: 10,
      tableData: []
    }
  },
  created () {
    this.endDay = new Date()
    this.startDay = new Date().setDate(new Date().getDate() - 7)
    this.onSearch()
  },
  methods: {
    onSearch () {
      let tGameId = 0
      if (this.gameId !== '') {
        tGameId = parseInt(this.gameId)
      }

      let sSendDay = 0
      let eSendDay = 0
      if (this.startDay !== '' && this.endDay !== '') {
        let sDay = new Date(this.startDay)
        let eDay = new Date(this.endDay)
        // sSendDay = '' + sDay.getFullYear() + ((sDay.getMonth() + 1) < 10 ? '0' + (sDay.getMonth() + 1) : (sDay.getMonth() + 1)) + (sDay.getDate() < 10 ? '0' + sDay.getDate() : sDay.getDate())
        // eSendDay = '' + eDay.getFullYear() + ((eDay.getMonth() + 1) < 10 ? '0' + (eDay.getMonth() + 1) : (eDay.getMonth() + 1)) + (eDay.getDate() < 10 ? '0' + eDay.getDate() : eDay.getDate())
        // sSendDay = parseInt(sSendDay)
        // eSendDay = parseInt(eSendDay)
        sSendDay = sDay.getTime()
        eSendDay = eDay.getTime()
      }

      console.log('tGameId:', tGameId, 'sSendDay:', sSendDay, ',eSendDay:', eSendDay, ',crtPage:', this.crtPage, ',pageSize:', this.pageSize)
      getRoleGameInfosTotal(tGameId, sSendDay, eSendDay, this.crtPage, this.pageSize).then((data) => {
        if (!data) {
          return
        }
        this.tableData = []
        let RoleGameInfoVO = getVO('RoleGameInfoVO')
        let pv = data.data.data
        let len = pv.data.length
        for (let i = 0; i < len; i++) {
          let vo = RoleGameInfoVO.decode(pv.data[i])
          console.log(vo)
          let _data = {}
          _data.playTimes = vo.playTimes.toNumber()
          _data.usePonts = vo.usePonts.toNumber()
          _data.winPonts = vo.winPonts.toNumber()
          _data.huibao = (_data.winPonts / _data.usePonts) * 100
          _data.huibao = _data.huibao.toFixed(2)
          _data.winPonts = _data.winPonts + ' (' + _data.huibao + '%)'
          _data.winTimes = vo.winTimes.toNumber()
          _data.zhongjiang = (_data.winTimes / _data.playTimes) * 100
          _data.zhongjiang = _data.zhongjiang.toFixed(2)
          _data.winTimes = _data.winTimes + ' (' + _data.zhongjiang + '%)'
          _data.failTimes = vo.failTimes.toNumber()
          _data.freeGameWinPoints = vo.freeGameWinPoints.toNumber()
          _data.mianfeihuibao = (_data.freeGameWinPoints / _data.usePonts) * 100
          _data.mianfeihuibao = _data.mianfeihuibao.toFixed(2)
          _data.freeGameWinPoints = _data.freeGameWinPoints + ' (' + _data.mianfeihuibao + '%)'
          _data.gameName = vo.gameId + ' (' + vo.gameName + ')'
          _data.num = vo.num
          this.tableData.push(_data)
        }
        this.totalPage = pv.intValues[1]
        console.log(this.tableData)
      })
    },
    onChange (item) {
      console.log(item)
      this.crtPage = item
      this.onSearch()
    }
  },
  computed: {
    tableColumns () {
      let cols = [
        {
          title: '游戏',
          key: 'gameName',
          align: 'left'
        },
        {
          title: '玩次数',
          key: 'playTimes',
          align: 'left'
        },
        {
          title: '人数',
          key: 'num',
          align: 'left'
        },
        {
          title: '获胜金币',
          key: 'winPonts',
          align: 'left'
        },
        {
          title: '使用金币',
          key: 'usePonts',
          align: 'left'
        },
        {
          title: '胜利次数',
          key: 'winTimes',
          align: 'left'
        },
        {
          title: '失败次数',
          key: 'failTimes',
          align: 'left'
        }
      ]
      return cols
    }
  }
}

</script>

<style scoped>
.log-str{
  font-size: 14px;
  margin-bottom: 2px;
}
.content{
  min-height: 460px;
}
.bottom-page{
  margin-top: 5px;
  margin-bottom: 10px;
  float: right;
}
</style>
